package com.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class NetTimeUtil {
	
	/**
	 * 当前时间加上时间后的时间字符串
	 * @param netTime时长
	 * @return
	 */
	public static String getTimeUtil(Date date,int netTime){
		long d = date.getTime();
		d=d+(netTime*60000);
		System.out.println("加上时长时间戳:"+d);
		SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		String format2 = format.format(date);
		System.out.println("现在时间:"+format2);
		
		
	    String duration = format.format(d);
		return duration;  
	}
	
	/**
	 * 当前时间距离时间点的时间(分钟)
	 * @param duration时间点
	 * @return
	 * @throws ParseException 
	 */
	public static int getDurationUtil(Date date,String duration) throws ParseException{
		long d = date.getTime();
		SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		Date parse = format.parse(duration);
		long time = parse.getTime();
		int t=(int) ((time-d)/60000);
		return t;  
	}
	
	
	public static void main(String[] args) {
		try {
			int durationUtil = getDurationUtil(new Date(), "2017-07-11 15:20:23");
			//System.out.println(getPareTimeUtil("2017-12-29 01:22:54", "yyyy-MM-dd HH:mm:ss"));
			
			
			System.out.println(durationUtil);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * 比较时间, 输出时间大于现在时间为true,小于等于为false
	 * @param time
	 * @param format
	 * @return
	 * @throws ParseException
	 */
	public static boolean getPareTimeUtil(String time ,String format) throws ParseException{
		boolean flg =false;
		if(time!=null){
			SimpleDateFormat sdf = new SimpleDateFormat(format);
				Date p = sdf.parse(time);
				long t = p.getTime();
				long newd = new Date().getTime();
				if( newd < t){
					flg = true;
				}
		}
		return flg;  
	}
	

	
	
	
}
